home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / wfimage / src / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-14  |  24.3 KB  |  634 lines

  1. /*****************************************************************************
  2.  *
  3.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1999-2001
  4.  * strandedUFO Productions.  All rights reserved.
  5.  *
  6.  * DISCLAIMER: This software is provided "as is".  No representations or
  7.  * warranties are made with respect to the accuracy, reliability,
  8.  * performance, currentness, or operation of this software, and all use is at
  9.  * your own risk.  The author will not assume any responsibility or
  10.  * liability whatsoever with respect to your use of this software.
  11.  *
  12.  *****************************************************************************
  13.  * test.c
  14.  * a program to test the waveforms.image BOOPSI class
  15.  * Written by P. Juhasz
  16.  *
  17.  */
  18.  
  19. #define __USE_SYSBASE        // perhaps only recognized by SAS/C
  20.  
  21. #include "waveforms.h"
  22. #include "waveformsbase.h"
  23.  
  24. #include <dos/dos.h>
  25.  
  26. #include <clib/dos_protos.h>
  27. #include <clib/alib_stdio_protos.h>
  28.  
  29. #include <proto/exec.h>
  30. #include <proto/dos.h>
  31. #include <proto/diskfont.h>
  32. #include <proto/intuition.h>
  33. #include <proto/icon.h>
  34.  
  35. #include <gadgets/button.h>
  36. #include <graphics/text.h>
  37.  
  38. #include <pragmas/dos_pragmas.h>
  39. #include <pragmas/exec_sysbase_pragmas.h>
  40. #include <pragmas/gadtools_pragmas.h>
  41.  
  42. #include <workbench/startup.h>
  43. #include <workbench/icon.h>
  44.  
  45. #include <dos.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49.  
  50. #define IDCMP_FLAGS  IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_GADGETUP | IDCMP_GADGETDOWN \
  51.                      | IDCMP_MOUSEMOVE | IDCMP_INTUITICKS | IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE  \
  52.                      | IDCMP_SIZEVERIFY | IDCMP_CHANGEWINDOW | IDCMP_REFRESHWINDOW
  53.  
  54. #define GD_Dummy     11
  55. #define GD_WaveSel   12
  56.  
  57. #define IMAGE_WID    60
  58. #define IMAGE_HGT    60
  59. #define IMAGE_TOP    20
  60. #define GADIMG_WID   27
  61. #define GADIMG_HGT   27
  62.  
  63. extern struct  ExecBase      *SysBase;
  64. extern struct  DosLibrary    *DOSBase;
  65. extern struct  Library       *DiskfontBase;
  66.  
  67. struct  IntuitionBase        *IntuitionBase = NULL;
  68.  
  69. STATIC struct  GfxBase       *GfxBase       = NULL;
  70. STATIC struct  UtilityBase   *UtilityBase   = NULL;
  71. STATIC struct  Library       *GadToolsBase  = NULL,
  72.                              *WorkbenchBase = NULL;
  73.  
  74. STATIC struct  ClassLibrary  *openclass( STRPTR name, ULONG version );
  75.  
  76.  
  77. STATIC ULONG wfimg_RGB32[98] =
  78. {
  79.    0x00200000, /* Record Header */
  80.    0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,
  81.    0x08888888,0x0CCCCCCC,0x0CCCCCCC,
  82.    0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
  83.    0x45555555,0x6DDDDDDD,0x9EEEEEEE,
  84.    0x5DDDDDDD,0x55555555,0x3DDDDDDD,
  85.    0xD2222222,0xD2222222,0xD2222222,
  86.    0xDBBBBBBB,0x7DDDDDDD,0x41111111,
  87.    0xCAAAAAAA,0x35555555,0xBAAAAAAA,
  88.    0x82222222,0x00000000,0x00000000,
  89.    0xD6666666,0x8AAAAAAA,0x0CCCCCCC,
  90.    0xDFFFFFFF,0xBAAAAAAA,0x45555555,
  91.    0x92222222,0x92222222,0x41111111,
  92.    0x00000000,0x45555555,0x00000000,      /* dark green background */
  93.    0x00000000,0xFBBBBBBB,0x59999999,      /* light green pen */
  94.    0xFFFFFFFF,0xFFFFFFFF,0x14444444,      /* yellow zero line */
  95.    0xC2222222,0x9AAAAAAA,0xC2222222,
  96.    0x20000000,0x00000000,0x20000000,
  97.    0xAEEEEEEE,0xAEEEEEEE,0xF3333333,
  98.    0xBEEEEEEE,0xAAAAAAAA,0x92222222,
  99.    0x59999999,0x10000000,0x5DDDDDDD,
  100.    0x31111111,0x39999999,0x71111111,
  101.    0x59999999,0x49999999,0xB6666666,
  102.    0x8AAAAAAA,0x8AAAAAAA,0x86666666,
  103.    0xAAAAAAAA,0x69999999,0xA2222222,
  104.    0x7DDDDDDD,0x86666666,0xC6666666,
  105.    0x92222222,0x35555555,0x82222222,
  106.    0x75555555,0xE3333333,0xEFFFFFFF,
  107.    0xDFFFFFFF,0x35555555,0x35555555,
  108.    0x00000000,0x45555555,0x9AAAAAAA,
  109.    0x59999999,0xBAAAAAAA,0xB2222222,
  110.    0x24444444,0x24444444,0x1CCCCCCC,
  111.    0x04444444,0x14444444,0x45555555,
  112.    0x00000000  /* Terminator */
  113. };
  114.  
  115.  
  116. /* These are: DETAILPEN, BLOCKPEN, TEXTPEN, SHINEPEN, SHADOWPEN, FILLPEN, FILLTEXTPEN,
  117.                BACKGROUNDPEN, HIGHLIGHTTEXTPEN, v39+ --> BARDETAILPEN, BARBLOCKPEN, BARTRIMPEN */
  118.  
  119. #define        WFI_PENS    12L
  120.  
  121. STATIC WORD    DriPens[]    = { 2, 0, 3, 2, 1, 5, 1, 0, 7, 6, 4, 5, 12, 13, 14, ~0 };
  122.  
  123. STATIC WORD    usepen[]     = { 2, 0, 3, 2, 1, 5, 1, 0, 7, 6, 4, 5, 12, 13, 14, ~0 };
  124.  
  125. STATIC char   *wavelabel[5] = { "Sine", "Triangle", "Ramp-up", "Ramp-down", "Square" };
  126.  
  127. STATIC BOOL    realosci     = FALSE;
  128.  
  129.  
  130.  
  131. /*__________________________________________________________________________________________
  132.  |                                                                                          |
  133.  |    Create and draw the new waveforms images                                              |
  134.  |__________________________________________________________________________________________*/
  135.  
  136. STATIC VOID make_waveforms( struct Window *win, struct DrawInfo *DrInfo, struct Image *img_a )
  137. {
  138.    LONG                    type, otype = 0L, outline, ix, wid, hgt, top;
  139.    ULONG                   tstore, zstore, ostore, ozpen = ~0, oopen = ~0;
  140.  
  141.    /* As we are reusing this image, we need to store some data for later */
  142.    if ( GetAttr( WFI_WaveType, img_a, &tstore ))      otype = (LONG)tstore;
  143.    if ( GetAttr( WFI_OsciPen, img_a, &ostore ))       oopen = (LONG)ostore;
  144.    if ( GetAttr( WFI_ZeroPen, img_a, &zstore ))       ozpen = (LONG)zstore;
  145.  
  146.    /*  Draw all possible waveforms images in two different sizes */
  147.    for ( ix = 0; ix < 11; ix += 10 ) {
  148.  
  149.       wid = IMAGE_WID - ix * 4 + 3;
  150.       hgt = IMAGE_HGT - ix * 4 + 3;
  151.       top = IMAGE_TOP + ix * 20;
  152.  
  153.       for ( outline = WF_SOLID_DISPLAY; outline <= WF_DOTTED_DISPLAY; outline++ ) {
  154.  
  155.          for ( type = WF_SINE_WAVE; type < WF_ALL_IMAGES; type++ ) {
  156.  
  157.             if ( SetAttrs( img_a, IA_Width, wid, IA_Height, hgt, WFI_WaveType, type,
  158.                            WFI_Outline, outline, WFI_BoxFrame, TRUE,
  159.                            WFI_ZeroPen, (ix < 10L ) ? ozpen : oopen,
  160.                            TAG_DONE ))
  161.  
  162.                /* we have just specified a new image, so draw it */
  163.                DrawImageState( win->RPort, img_a,
  164.                                  win->BorderLeft + 20 + ( type * 16 ) + ( type * wid ),
  165.                                  win->BorderTop + top + (( hgt * 3 / 2 ) * outline ),
  166.                                  IDS_NORMAL, DrInfo );
  167.          }
  168.       }
  169.    }
  170.    /* Since we use only one object, it needs resetting to display correctly in our gadget */
  171.    SetAttrs( img_a, IA_Width, GADIMG_WID, IA_Height, GADIMG_HGT, WFI_WaveType, otype,
  172.              WFI_Outline, WF_DOTTED_DISPLAY, WFI_BoxFrame, FALSE, TAG_DONE );
  173. }
  174.  
  175.  
  176. /*__________________________________________________________________________________________
  177.  |                                                                                          |
  178.  |    This is the main gui handler                                                          |
  179.  |__________________________________________________________________________________________*/
  180.  
  181.  
  182. STATIC VOID do_user_loop( struct Window *win, struct DrawInfo *DrInfo, struct Image *img_a,
  183.                           struct Image *img_b, struct Gadget *testGList, struct Gadget *testGad )
  184. {
  185.    struct IntuiMessage    *imsg, Mesg;
  186.    BOOL                    going = TRUE;
  187.    ULONG                   sigr, winmask = 1 << ( win->UserPort->mp_SigBit );
  188.    ULONG                   code, store;
  189.    LONG                    type = WF_SINE_WAVE;
  190.  
  191.    while( going )
  192.    {
  193.       sigr = Wait( winmask );
  194.  
  195.       if ( sigr & winmask )                        /* it's our Window  */
  196.       {
  197.          while ( imsg = GT_GetIMsg( win->UserPort ))
  198.          {
  199.             CopyMem(( char *)imsg, ( char *)&Mesg, (LONG)sizeof( struct IntuiMessage ));
  200.             GT_ReplyIMsg( imsg );
  201.  
  202.             switch ( Mesg.Class )
  203.             {
  204.                case  IDCMP_REFRESHWINDOW:
  205.  
  206.                   BeginRefresh( win );
  207.                   make_waveforms( win, DrInfo, img_a );
  208.                   EndRefresh( win, TRUE );
  209.                   break;
  210.  
  211.                case IDCMP_CLOSEWINDOW:
  212.                   going = FALSE;
  213.                   break;
  214.  
  215.                case IDCMP_VANILLAKEY:
  216.  
  217.                   switch ( Mesg.Code )
  218.                   {
  219.                      case  27:
  220.                      case 'q':
  221.                      case 'Q':
  222.                        going = FALSE;
  223.                        break;
  224.                      default: break;
  225.                   }
  226.                   break;
  227.  
  228.                case  IDCMP_IDCMPUPDATE:
  229.                   //testIDCMPUpdate();
  230.                   break;
  231.  
  232.                case  IDCMP_CHANGEWINDOW:
  233.                   //testChangeWindow();
  234.                   break;
  235.  
  236.                case  IDCMP_GADGETDOWN:
  237.  
  238.                   code = (( struct Gadget *)Mesg.IAddress )->GadgetID;
  239.  
  240.                   switch ( code ) {
  241.  
  242.                      case GD_Dummy:
  243.                         break;
  244.  
  245.                      default: break;
  246.                   }
  247.                   break;
  248.  
  249.                case  IDCMP_GADGETUP:
  250.  
  251.                   code = (( struct Gadget *)Mesg.IAddress )->GadgetID;
  252.  
  253.                   switch ( code ) {
  254.  
  255.                      case GD_WaveSel:
  256.  
  257.                         if ( GetAttr( WFI_WaveType, img_a, &store ))     type = (LONG)store;
  258.  
  259.                         /* cycle through the waveforms on each gadgethit */
  260.                         if ( type >= WF_SQUARE_WAVE )       type = WF_SINE_WAVE;
  261.                         else                                type++;
  262.  
  263.                         SetAttrs( img_a, WFI_WaveType, (ULONG)type, TAG_DONE );
  264.  
  265.                         /* do the alternate image as well */
  266.                         SetAttrs( img_b, WFI_WaveType, (ULONG)type, TAG_DONE );
  267.  
  268.                         GT_SetGadgetAttrs( testGad, win, NULL,
  269.                                            GTTX_Text,     (ULONG)wavelabel[type],
  270.                                            GTTX_CopyText, TRUE,
  271.                                            TAG_DONE );
  272.                         RefreshGList( testGList, win, NULL, -1L );
  273.                         break;
  274.  
  275.                      default: break;
  276.                   }
  277.                   break;
  278.  
  279.                default: break;
  280.  
  281.             }
  282.          }
  283.       }
  284.    }
  285. }
  286.  
  287.  
  288. /*__________________________________________________________________________________________
  289.  |                                                                                          |
  290.  |    Make a solid or dotted waveform image object with default values                      |
  291.  |__________________________________________________________________________________________*/
  292.  
  293. STATIC struct Image *makeDefImage( struct DrawInfo *DrInfo, ULONG outl )
  294. {
  295.    return( NewObject( NULL, "waveformiclass",
  296.                       IA_Width,         GADIMG_WID,
  297.                       IA_Height,        GADIMG_HGT,
  298.                       IA_FGPen,         (ULONG)usepen[0L],
  299.                       IA_BGPen,         (ULONG)usepen[4L],
  300.                       IA_Left,          0L,
  301.                       IA_Top,           0L,
  302.                       SYSIA_DrawInfo,   DrInfo,
  303.                       WFI_WaveType,     WF_SINE_WAVE,
  304.                       WFI_WaveShape,    0L,
  305.                       WFI_Outline,      outl,
  306.                       WFI_BoxFrame,     FALSE,
  307.                       WFI_OsciPen,      ( realosci ) ? (ULONG)usepen[12L] : ~0,
  308.                       WFI_WavePen,      ( realosci ) ? (ULONG)usepen[13L] : ~0,
  309.                       WFI_ZeroPen,      ( realosci ) ? (ULONG)usepen[14L] : ~0,
  310.                       TAG_DONE ));
  311.  
  312. }
  313.  
  314.  
  315. /*__________________________________________________________________________________________
  316.  |                                                                                          |
  317.  |    Test the waveforms images and the newly created waveforms.image class                 |
  318.  |__________________________________________________________________________________________*/
  319.  
  320. STATIC LONG run_test( struct Window *win, struct DrawInfo *DrInfo, APTR vinfo )
  321. {
  322.    struct WFIBase         *cb;
  323.    struct Image           *img_a, *img_b;
  324.    struct ClassLibrary    *gadLib;
  325.    LONG                    rtc = 0L;
  326.  
  327.    if ( cb = (struct WFIBase *)AllocMem( sizeof( struct WFIBase ), MEMF_PUBLIC | MEMF_CLEAR )) {
  328.  
  329.       if ( raiseClass( cb )) {
  330.  
  331.          /* Make a new image object with default data, we can reuse it any number of times */
  332.          if ( img_a = makeDefImage( DrInfo, WF_DOTTED_DISPLAY )) {
  333.  
  334.             /* ...and just for the hell of it, make a separate one for our selected gadget */
  335.             /*       using the 'solid' display - looks real cool - doesn't it ?  */
  336.             if ( img_b = makeDefImage( DrInfo, WF_SOLID_DISPLAY )) {
  337.  
  338.                /* Print all the possible waveform images into the window */
  339.                make_waveforms( win, DrInfo, img_a );
  340.  
  341.                if ( gadLib = openclass( "gadgets/button.gadget", LIBRARY_VER )) {
  342.  
  343.                   UWORD                   sequ;
  344.                   struct NewGadget        ng = { 330, 250, GADIMG_WID + 25L, 13L,
  345.                                                  NULL, NULL, GD_Dummy, 0, NULL, NULL };
  346.                   struct Gadget          *g, *testGList = NULL, *testGads[2];
  347.  
  348.                   if (( g = CreateContext( &testGList ))) {
  349.  
  350.                      ng.ng_VisualInfo = vinfo;
  351.  
  352.                      /* Make one gadget for the list - I kept getting hits on exiting when
  353.                            there is just the one BOOPSI button.gadget on its own... */
  354.                      if ( testGads[0] = g = CreateGadget((ULONG)TEXT_KIND, g, &ng, TAG_DONE )) {
  355.  
  356.                         /* Our display gadget which cycles through all waveforms */
  357.                         if ( testGads[1] = g = NewObject( NULL, "button.gadget",
  358.                                      GA_Previous,        (ULONG)g,
  359.                                      GA_Top,             240L,
  360.                                      GA_Left,            280L,
  361.                                      GA_Width,           GADIMG_WID + 5L,
  362.                                      GA_Height,          GADIMG_HGT + 5L,
  363.                                      GA_DrawInfo,        DrInfo,
  364.                                      GA_ID,              GD_WaveSel,
  365.                                      //GA_Immediate,       TRUE,
  366.                                      GA_RelVerify,       TRUE,
  367.                                      GA_LabelImage,      img_a,
  368.                                      GA_Image,           img_a,
  369.                                      GA_SelectRender,    img_b,
  370.                                      BUTTON_BevelStyle,  BVS_THIN,
  371.                                      TAG_DONE )) {
  372.  
  373.                            sequ = AddGList( win, testGList, (UWORD)~0, -1, NULL );
  374.                            GT_SetGadgetAttrs( testGads[0], win, NULL,
  375.                                               GTTX_Text,          (ULONG)wavelabel[0],
  376.                                               GTTX_CopyText,      TRUE,
  377.                                               GTTX_FrontPen,      HIGHLIGHTTEXTPEN,
  378.                                               //GTTX_BackPen,       SHADOWPEN,
  379.                                               TAG_DONE );
  380.                            RefreshGList( testGList, win, NULL, -1L );
  381.  
  382.                            /* From here on the user is in control */
  383.  
  384.                            do_user_loop( win, DrInfo, img_a, img_b, testGList, testGads[0] );
  385.  
  386.                            /* User got fed up, closed the window or pressed quit */
  387.  
  388.                            RemoveGList( win, testGList, -1L );
  389.                            testGads[1]->GadgetRender = testGads[1]->SelectRender = NULL;
  390.                            DisposeObject( testGads[1] );
  391.                            testGads[1] = testGads[0]->NextGadget = NULL;
  392.                         }
  393.                      }
  394.                      FreeGadgets( testGList );
  395.                   }
  396.                   CloseLibrary(( struct Library *)gadLib );
  397.                }
  398.                DisposeObject( img_b );
  399.             }
  400.             DisposeObject( img_a );
  401.          }
  402.          dropClass( cb );
  403.       }
  404.       FreeMem( cb, sizeof( struct WFIBase ));
  405.    } else   rtc = 10L;
  406.  
  407.    return( rtc );
  408. }
  409.  
  410.  
  411. /*__________________________________________________________________________________________
  412.  |                                                                                          |
  413.  |    Get some BOOPSI gadgets and open a window to display them.                            |
  414.  |__________________________________________________________________________________________*/
  415.  
  416. STATIC VOID gui_setup( struct Screen *scr, LONG ownscreen )
  417. {
  418.    struct Window          *win;
  419.    struct DrawInfo        *DrInfo = NULL;
  420.    APTR                    vinfo;
  421.  
  422.    if ( GadToolsBase = OpenLibrary( "gadtools.library", LIBRARY_VER )) {
  423.  
  424.       if ( DrInfo = GetScreenDrawInfo( scr )) {
  425.  
  426.          if ( vinfo = GetVisualInfo( scr, TAG_DONE )) {
  427.  
  428.             ULONG          wintag = ( ownscreen ) ? WA_CustomScreen : WA_PubScreen;
  429.             UWORD          wleft = 180, wtop = 75, WWidth = 440, WHeight = 320;
  430.  
  431.             if ( win = OpenWindowTags( NULL,
  432.                                     WA_Title,             "waveforms.image Test",
  433.                                     WA_Left,              wleft,
  434.                                     WA_Top,               wtop,
  435.                                     WA_Width,             WWidth,
  436.                                     WA_Height,            WHeight,
  437.                                     WA_IDCMP,             IDCMP_FLAGS,
  438.                                     WA_DragBar,           TRUE,
  439.                                     WA_DepthGadget,       TRUE,
  440.                                     WA_CloseGadget,       TRUE,
  441.                                     WA_SimpleRefresh,     TRUE,
  442.                                     WA_SmartRefresh,      TRUE,
  443.                                     //WA_NoCareRefresh,     TRUE,
  444.                                     WA_Activate,          TRUE,
  445.                                     wintag,               scr,
  446.                                     WA_AutoAdjust,        TRUE,
  447.                                     WA_PubScreenFallBack, TRUE,
  448.                                     TAG_DONE )) {
  449.  
  450.                GT_RefreshWindow( win, NULL );
  451.  
  452.                // Screen and window are open, all ready for the big event...
  453.                                                       // shout if something went wrong
  454.                if ( run_test( win, DrInfo, vinfo ))      DisplayBeep( scr );
  455.  
  456.                CloseWindow( win );
  457.             }
  458.             FreeVisualInfo( vinfo );
  459.          }
  460.          FreeScreenDrawInfo( scr, DrInfo );
  461.       }
  462.       CloseLibrary( GadToolsBase );
  463.    }
  464. }
  465.  
  466.  
  467. /*__________________________________________________________________________________________
  468.  |                                                                                          |
  469.  |    Open a custom or public screen and allocate pens if latter.                           |
  470.  |__________________________________________________________________________________________*/
  471.  
  472. STATIC VOID intui_setup( LONG ownscreen )
  473. {
  474.    struct Screen          *scr;
  475.    LONG                    ix = WFI_PENS, iy;
  476.    ULONG                   red, blue, green;
  477.    ULONG                   lokpen[16] = { 0 };
  478.  
  479.    if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", LIBRARY_VER )) {
  480.  
  481.       if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", LIBRARY_VER )) {
  482.  
  483.          if ( ownscreen ) {
  484.  
  485.             scr = OpenScreenTags( NULL,
  486.                                   SA_Left,          0,
  487.                                   SA_Top,           0,
  488.                                   SA_Width,         800,
  489.                                   SA_Height,        600,
  490.                                   SA_Depth,         5,
  491.                                   SA_LikeWorkbench, TRUE,
  492.                                   SA_Type,          CUSTOMSCREEN,
  493.                                   SA_AutoScroll,    TRUE,
  494.                                   SA_Pens,          usepen,
  495.                                   SA_SysFont,       TRUE,
  496.                                   SA_Colors32,      wfimg_RGB32,
  497.                                   SA_FullPalette,   TRUE,
  498.                                   SA_SharePens,     TRUE,
  499.                                   SA_Title,         "WaveForms image test",
  500.                                   TAG_DONE );
  501.  
  502.          } else {
  503.  
  504.             if ( scr = LockPubScreen( "Workbench" )) {
  505.  
  506.                while (( usepen[ix] != -1L ) && ( ix < 15 )) {
  507.  
  508.                   iy    = (LONG)DriPens[ix];
  509.                   red   = wfimg_RGB32[ iy * 3 + 1 ];
  510.                   green = wfimg_RGB32[ iy * 3 + 2 ];
  511.                   blue  = wfimg_RGB32[ iy * 3 + 3 ];
  512.  
  513.                   usepen[ix] = (( lokpen[ix] = (ULONG)ObtainBestPen( scr->ViewPort.ColorMap,
  514.                                                                     red, green, blue,
  515.                                                                     TAG_DONE )) == ~0 )
  516.                      ? DriPens[ix] : (WORD)lokpen[ix];
  517.  
  518.                   ix++;
  519.                }
  520.             }
  521.          }
  522.  
  523.          if ( scr ) {
  524.  
  525.             gui_setup( scr, ownscreen );
  526.  
  527.             if ( ownscreen )        CloseScreen( scr );
  528.             else {
  529.                for ( ix = WFI_PENS; ix < 15; ix++ )
  530.                   ReleasePen( scr->ViewPort.ColorMap, lokpen[ix] );
  531.                UnlockPubScreen( NULL, scr );
  532.             }
  533.          }
  534.          CloseLibrary((struct Library *)GfxBase );
  535.       }
  536.       CloseLibrary((struct Library *)IntuitionBase );
  537.    }
  538. }
  539.  
  540.  
  541. /*__________________________________________________________________________________________
  542.  |                                                                                          |
  543.  |    Open libraries, open a screen and a window on it, then run the classtest              |
  544.  |__________________________________________________________________________________________*/
  545.  
  546. int main( int argc, char **argv )
  547. {
  548.    struct WBArg            wbArg = { NULL, NULL };
  549.    struct WBStartup       *wbs;
  550.    LONG                    ownscreen = 0L;
  551.  
  552.    if ( UtilityBase = (struct UtilityBase *)OpenLibrary( "utility.library", LIBRARY_VER )) {
  553.  
  554.       if ( WorkbenchBase = OpenLibrary( "workbench.library", LIBRARY_VER )) {
  555.  
  556.          if ( argc ) {                       // Are we running from CLI...
  557.  
  558.             wbArg.wa_Lock = GetProgramDir();
  559.             wbArg.wa_Name = argv[0];
  560.  
  561.             if ( wbs = AllocMem( sizeof( struct WBStartup ), MEMF_PUBLIC | MEMF_CLEAR ))
  562.                wbs->sm_ArgList = &wbArg;
  563.  
  564.          } else                              // ...or invoked via workbench ?
  565.  
  566.             wbs = ( struct WBStartup *)argv;
  567.  
  568.          if ( wbs ) {
  569.  
  570.             char                   *typevalue = NULL;
  571.             LONG                    localdir = CurrentDir( wbs->sm_ArgList[0].wa_Lock );
  572.             struct DiskObject      *DiskObj = NULL;
  573.             struct Library         *IconsBase = NULL;
  574.  
  575.             if ( IconsBase = OpenLibrary( ICONNAME, LIBRARY_VER )) {
  576.  
  577.                if ( DiskObj = GetDiskObject( wbs->sm_ArgList[0].wa_Name )) {
  578.                   if ( DiskObj->do_ToolTypes ) {
  579.                      if ( typevalue = FindToolType( DiskObj->do_ToolTypes, "OWNSCREEN" )) {
  580.                         ownscreen = ( Stricmp( typevalue, "YES" ) == 0 ) ? 1 : 0;
  581.                      }
  582.                      if ( typevalue = FindToolType( DiskObj->do_ToolTypes, "REALOSCI" )) {
  583.                         realosci = ( Stricmp( typevalue, "YES" ) == 0 ) ? TRUE : FALSE;
  584.                      }
  585.                   }
  586.                   FreeDiskObject( DiskObj );
  587.                   DiskObj = NULL;
  588.                }
  589.                if ( localdir != -1L )
  590.                {
  591.                   CurrentDir( localdir );
  592.                   localdir = NULL;
  593.                }
  594.  
  595.                CloseLibrary( IconsBase );
  596.             }
  597.             if ( argc && wbs )      FreeMem( wbs, sizeof( struct WBStartup ));
  598.          }
  599.  
  600.          intui_setup( ownscreen );                 // All okay, so carry on...
  601.  
  602.          CloseLibrary( WorkbenchBase );
  603.       }
  604.       CloseLibrary((struct Library *)UtilityBase );
  605.    }
  606.    return( EXIT_SUCCESS );
  607. }
  608.  
  609.  
  610. /*__________________________________________________________________________________________
  611.  |                                                                                          |
  612.  |    Try opening the class library from a number of common places                          |
  613.  |__________________________________________________________________________________________*/
  614.  
  615. STATIC struct ClassLibrary *openclass( STRPTR name, ULONG version )
  616. {
  617.    struct Library   *retval;
  618.    UBYTE             buffer[256];
  619.  
  620.    if (( retval = OpenLibrary( name, version )) == NULL )
  621.    {
  622.       sprintf( buffer, "classes/%s", name );
  623.       if (( retval = OpenLibrary( buffer, version )) == NULL )
  624.       {
  625.          sprintf( buffer, "Sys:classes/%s", name );
  626.          retval = OpenLibrary( buffer, version );
  627.       }
  628.    }
  629.    return((struct ClassLibrary *)retval );
  630. }
  631.  
  632.  
  633.  
  634.